<template>
  <el-drawer v-model="drawer" :direction="direction" :show-close="false">
    <template #header="{ close, titleId, titleClass }">
      <h4 :id="titleId" :class="titleClass">This is a custom header!</h4>
      <el-button type="danger" @click="close">
        <el-icon class="el-icon--left"><CircleCloseFilled /></el-icon>
        Close
      </el-button>
    </template>
    <template #default>
      <div>
        <el-form :model="formData">
          <el-form-item label="Value" :label-width="formLabelWidth">
            <!-- <el-input v-model="formData.value" autocomplete="off" /> -->
            <WebAutocomplete
              :value="formData.value"
              @selectChanged="valueSelectChanged"
            ></WebAutocomplete>
          </el-form-item>
          <el-form-item label="Link" :label-width="formLabelWidth">
            <el-input v-model="formData.link" autocomplete="off" />
          </el-form-item>
          <el-form-item label="Address" :label-width="formLabelWidth">
            <el-input v-model="formData.address" autocomplete="off" />
          </el-form-item>
        </el-form>
      </div>
    </template>
    <template #footer>
      <div style="flex: auto">
        <el-button @click="cancelClick">cancel</el-button>
        <el-button type="primary" @click="confirmClick">confirm</el-button>
      </div>
    </template>
  </el-drawer>
</template>

<script lang="ts" setup>
import { ref } from 'vue'
import { ElMessageBox } from 'element-plus'
import WebAutocomplete from './WebAutocomplete.vue'
import { useWebStore } from '../../stores/web'
import { storeToRefs } from 'pinia'
const formLabelWidth = '80px'
const webStore = useWebStore()

const { drawer, formData } = storeToRefs(webStore)

const direction = ref('rtl')
const radio1 = ref('Option 1')

const valueSelectChanged = (item) => {
  console.log('valueSelectChanged')
  formData.value = item.value
  console.log(item.value)
}

function cancelClick() {
  webStore.drawer = false
}
function confirmClick() {
  ElMessageBox.confirm(`Are you confirm to chose ${radio1.value} ?`)
    .then(() => {
      webStore.drawer = false
    })
    .catch(() => {
      // catch error
    })
}
</script>
